package com.ycu.jk16.mall.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ycu.jk16.mall.dao.UserDao;
import com.ycu.jk16.mall.domain.User;
import com.ycu.jk16.mall.service.UserService;

@Service("userService")
public class UserServiceImpl implements UserService {

	/**
	 * 注入持久层对象
	 */
	@Autowired
	private UserDao userDao;

	@Override
	public void register(User user) {
		userDao.insertUser(user);
	}

	@Override
	public User login(String username, String password) {
		return userDao.selectByUserNameAndPwd(username, password);
	}

	@Override
	public List<User> getUserList(Map<String, Object> params) {
		return userDao.selectUserWithParam(params);
	}

	@Override
	public boolean checkUsername(String username) {
		User user = userDao.selectUserByUsername(username);
		return user==null;
	}

	@Override
	public boolean checkEmail(String email) {
		User user = userDao.selectUserByEmail(email);
		return user==null;
	}

	@Override
	public void updateUser(User user) {
		userDao.updateUser(user);
	}

	@Override
	public User findUserById(Integer id) {
		return userDao.selectById(id);
	}

	@Override
	public Integer countUser() {
		return userDao.countUser();
	}

	@Override
	public User findUserByUsername(String username) {
		return userDao.selectUserByUsername(username);
	}

	@Override
	public User findUserByEmail(String email) {
		return userDao.selectUserByEmail(email);
	}
}
